﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ccit.ClassLibrary;
using System.Web.UI.HtmlControls;
using Newtonsoft.Json;

namespace Ccit.SysPlat.Purview
{
    /// <summary>
    /// Description: 系统平台权限菜单 -> 权限管理编辑页面
    /// Author: tim 2010-03-04
    /// </summary>
    public partial class sys_purview_edit : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _hidRoleId.Value = (null != Request.QueryString["roleId"]) ? Request.QueryString["roleId"].ToString() : string.Empty;
                /* 能否编辑标志 0:不可以 1:可以 */
                ViewState["edit"] = (null != Request.QueryString["edit"]) ? Request.QueryString["edit"].ToString() : "0";
                _hidOrganId.Value = (null != Request.QueryString["organId"]) ? Request.QueryString["organId"].ToString() : "1";                
                initializePage();
            }
        }


        private void initializePage()
        {
            MsLoginUser loginUser = Session["LogUserInfo"] as MsLoginUser;
            _hidUserType.Value = loginUser.userType.ToString("D");

            ViewState["MODPRV"] = string.Empty;
            ViewState["OPERPRV"] = string.Empty;
            txtRoleName.Text = string.Empty;

            string roleId = _hidRoleId.Value;
            RoleBLL roleBLL = new RoleBLL();
            MsRole msRole = roleBLL.GetRoleInfo(roleId);
            initRoleInfo(msRole); //初始化角色基本信息

            //初始化角色权限信息
            List<MsMenu> lstMenu = roleBLL.GetAdminMenus(loginUser.userId, loginUser.userType, loginUser.organId);
            buildPrvMenus(lstMenu, msRole,loginUser.userType);

            #region logout code tim 
            //if (_hidRoleId.Value != "")
            //{
            //    RoleNET oRole = new RoleNET(Int32.Parse(_hidRoleId.Value));
            //    txtRoleName.Text = oRole.RoleName;
            //    _hidRangeType.Value = oRole.UserSign;
            //    _hidRoleRange.Value = oRole.UserRangeId;
            //    txtRoleRange.Text = oRole.UserRangeName;
            //    ViewState["ROLEPURVIEW"] = oRole;
            //}

            //createPurViewMenus();
            //ViewState["ROLEPURVIEW"] = null;
            #endregion

            loginUser = null;
            msRole = null;
            roleBLL.Release();
            roleBLL = null;
        }

        private void initRoleInfo(MsRole msRole)
        {
            if (null == msRole) return;

            txtRoleName.Text = msRole.roleName;
            _hidRangeType.Value = msRole.rangeType.ToString("D");
            _hidRoleRange.Value = msRole.rangeIds;
            txtRoleRange.Text = msRole.rangeNames;

            if (msRole.canEdit == eTrueFalse.FALSE) aSelRange.Attributes["style"] = "display:none";

            ViewState["MODPRV"] = msRole.modPrvIds;
            ViewState["OPERPRV"] = msRole.lstMenuPrv.ToString<MsPurview>("menuId");
        }

        /// <summary>
        /// 构建权限设置页面
        /// </summary>
        /// <param name="lstPrvMenu"></param>
        /// <param name="msRole"></param>
        private void buildPrvMenus(List<MsMenu> lstPrvMenu, MsRole msRole,eUserType enUserType)
        {
            if (enUserType == eUserType.ORDINARY) filterPrvMenus(ref lstPrvMenu);

            IEnumerable<IGrouping<string, MsMenu>> menuGroup = lstPrvMenu.GroupBy(m => m.layCode.Substring(0, 6));

            foreach (IGrouping<string, MsMenu> eGroup in menuGroup)
            {
                int itemCount = eGroup.Count();
                if (itemCount == 1)
                {                    
                    MsMenu layOneMenu = eGroup.SingleOrDefault(m => m.lay == "1");
                    addModMenu(layOneMenu);                   
                }
                else {
                    addOperMenu(eGroup,msRole);
                }
            }
        }


        /// <summary>
        /// 此处需要进行过滤
        ///   业务逻辑:如果2级下的所有3级均不需要设置权限，那么2级也不展现
        ///            如果1级下的所有2级均不需要展现，那么1级也不展现
        /// </summary>
        /// <param name="lstPrvMenu"></param>
        private void filterPrvMenus(ref List<MsMenu> lstPrvMenu)
        {          
            IEnumerable<IGrouping<string, MsMenu>> menuGroup = lstPrvMenu.GroupBy(m => m.layCode.Substring(0, 6));
            bool bOneShow = false;
            bool bTwoShow = false;
            foreach (IGrouping<string, MsMenu> eGroup in menuGroup)
            {
                bOneShow = false;
                IEnumerable<MsMenu> layTwoMenus = eGroup.Where(t => t.lay == "2");                
                foreach (MsMenu eTwoMenu in layTwoMenus)
                {
                    bTwoShow = false;
                    if (eTwoMenu.isLeaf == "1")
                    {
                        if ((eTwoMenu.purviewSet == "1") && !bOneShow) bOneShow = true;
                        bTwoShow = (eTwoMenu.purviewSet == "1") ? true : false;
                    }
                    else
                    {
                        IEnumerable<MsMenu> layThreeMenus = eGroup.Where(th => (th.lay == "3") && 
                                                            th.layCode.Substring(0,12).Equals(eTwoMenu.layCode));
                        foreach (MsMenu eThreeMenu in layThreeMenus)
                        {
                            if (eThreeMenu.purviewSet.Equals("1"))
                            {
                                if(!bTwoShow) bTwoShow = true;
                                if(!bOneShow) bOneShow = true;
                            }
                            else
                                lstPrvMenu.Remove(eThreeMenu);
                        }
                    }

                    if (!bTwoShow) lstPrvMenu.Remove(eTwoMenu);                    
                }

                if (!bOneShow) lstPrvMenu.Remove(eGroup.SingleOrDefault(o => o.lay == "1"));
            }
        }


        #region 创建MOD菜单
        private void addModMenu(MsMenu layOneMenu)
        {
            if (null == layOneMenu) return;

            string menuId = layOneMenu.menuId;
            string menuName = layOneMenu.menuName;
            HtmlTableRow trow = createModTableRow(menuId, menuName);
            tbPurview.Rows.Add(trow);
        }

        private HtmlTableRow createModTableRow(string menuId, string menuName)
        {
            /* 创建菜单行规则:
             *   0. span : empty &nbsp;
             *   1. hidden : 存放参数.参数形式:leaf_menuid_DataRangeSign
             *              leaf 0: 非叶子; 1:叶子; 2: 模块 (为自定义，为编程方便，数据库中没此枚举值);
             *              menuid: 菜单Id
             *              DataRangeSign: 数据范围标志 0:不需要 1:需要设置             
             *   2. checkbox **/

            HtmlTableRow trow = new HtmlTableRow();
            trow.Attributes.Add("class", "darkrow1");

            HtmlTableCell tcell;
            HtmlInputHidden hid;
            HtmlInputCheckBox chk;
            HtmlGenericControl span;
            HtmlGenericControl spanEmpty;
            bool bCheck = false;

            tcell = new HtmlTableCell();
            spanEmpty = new HtmlGenericControl();
            spanEmpty.ID = "span_mod_empty_" + menuId;
            spanEmpty.InnerHtml = "&nbsp;";
            tcell.Controls.Add(spanEmpty);

            hid = new HtmlInputHidden();
            hid.ID = "hid_mod_param_" + menuId;
            hid.Value = "2_" + menuId + "_0";
            tcell.Controls.Add(hid);

            span = new HtmlGenericControl();
            span.ID = "span_mod_" + menuId;
            span.InnerHtml = "&nbsp;" + menuName + "&nbsp;";
                        
            if (!string.IsNullOrEmpty(ViewState["MODPRV"].ToString()))
            {
                StringLib oString = new StringLib(ViewState["MODPRV"].ToString());
                bCheck = oString.Contains(menuId);
                oString = null;                
            }
            else
                bCheck = false;

            chk = new HtmlInputCheckBox();
            chk.ID = "chk_mod_" + menuId;
            chk.Checked = bCheck;
            chk.Attributes.Add("class", "checkbox");
            tcell.Controls.Add(chk);
            tcell.Controls.Add(span);

            trow.Cells.Add(tcell);
            return trow;
        }
        #endregion

        #region 创建OPER菜单
        private void addOperMenu(IGrouping<string, MsMenu> modGroup, MsRole msRole)
        {
            if (null == modGroup) return;

            MsMenu layOneMenu = modGroup.SingleOrDefault(m => m.lay == "1");

            string menuId = layOneMenu.menuId;
            string menuName = layOneMenu.menuName;
            createLayOneOperMenu(modGroup, menuId, menuName,msRole);
        }

        private void createLayOneOperMenu(IGrouping<string, MsMenu> modGroup, string menuId, string menuName, MsRole msRole)
        {
            /* 创建菜单行规则:
             *   0. span : empty &nbsp;
             *   1. hidden : 存放参数.参数形式:leaf_menuid_DataRangeSign
             *              leaf 0: 非叶子; 1:叶子; 2: 模块 (为自定义，为编程方便，数据库中没此枚举值);
             *              menuid: 菜单Id
             *              DataRangeSign: 数据范围标志 0:不需要 1:需要设置             
             *   2. checkbox **/

            HtmlTableRow trow = new HtmlTableRow();
            trow.Attributes.Add("class", "darkrow1");

            HtmlTableCell tcell;
            HtmlInputHidden hid;
            HtmlInputCheckBox chk;
            HtmlGenericControl span;
            HtmlGenericControl spanEmpty;
            string chkLayOneId = "chk_oper_" + menuId;

            tcell = new HtmlTableCell();

            spanEmpty = new HtmlGenericControl();
            spanEmpty.ID = "span_oper_empty_" + menuId;
            spanEmpty.InnerHtml = "&nbsp;";
            tcell.Controls.Add(spanEmpty);

            hid = new HtmlInputHidden();
            hid.ID = "hid_oper_param_" + menuId;
            hid.Value = "0_" + menuId + "_0";
            tcell.Controls.Add(hid);

            span = new HtmlGenericControl();
            span.ID = "span_oper_" + menuId;
            span.InnerHtml = "&nbsp;" + menuName + "&nbsp;";

            chk = new HtmlInputCheckBox();
            chk.ID = chkLayOneId;
            chk.Attributes.Add("onclick", "doCheckChange('" + chkLayOneId + "')");
            chk.Attributes.Add("class", "checkbox");
            tcell.Controls.Add(chk);
            tcell.Controls.Add(span);

            trow.Cells.Add(tcell);
            tbPurview.Rows.Add(trow);
                        
            createLayTwoOperMenus(ref chk, modGroup, menuId,msRole);
        }

        private void createLayTwoOperMenus(ref HtmlInputCheckBox chkLayOne, IGrouping<string, MsMenu> modGroup, 
                                                string layOneMenuId, MsRole msRole)
        {
            IEnumerable<MsMenu> layTwoQuery = modGroup.Where(m => m.lay == "2");
            
            /* 创建菜单行规则:
             *   0. span : empty &nbsp;
             *   1. hidden : 存放参数.参数形式:leaf_menuid_DataRangeSign
             *              leaf 0: 非叶子; 1:叶子; 2: 模块 (为自定义，为编程方便，数据库中没此枚举值);
             *              menuid: 菜单Id
             *              DataRangeSign: 数据范围标志 0:不需要 1:需要设置             
             *   2. checkbox **/

            //XmlNode oLayTwo;
            //int iCount = oLayTwos.Count;
            HtmlTableRow trow;
            HtmlTableCell tcell;
            HtmlInputHidden hid;
            HtmlInputCheckBox chk;
            HtmlGenericControl span;
            HtmlGenericControl spanEmpty;

            string menuId = string.Empty;
            string menuName = string.Empty;
            string isLeaf = string.Empty;
            string chkLayTwoId = string.Empty;
            string rangeSet = string.Empty;  //数据范围标志
            bool bTwoCheckAll = true;
            bool bTwoCheck = true;
            string sParamId = string.Empty;

            foreach(MsMenu eTwoMenu in layTwoQuery)
            {
                menuId = eTwoMenu.menuId;
                menuName = eTwoMenu.menuName;
                isLeaf = eTwoMenu.isLeaf;
                sParamId = layOneMenuId + "_" + menuId;
                chkLayTwoId = "chk_oper_" + sParamId;
                rangeSet = eTwoMenu.rangeSet;

                trow = new HtmlTableRow();
                trow.Attributes.Add("class", "darkrow2");
                tcell = new HtmlTableCell();

                spanEmpty = new HtmlGenericControl();
                spanEmpty.ID = "span_oper_empty_" + sParamId;
                spanEmpty.InnerHtml = "&nbsp;&nbsp;&nbsp;&nbsp;";
                tcell.Controls.Add(spanEmpty);

                hid = new HtmlInputHidden();
                hid.ID = "hid_oper_param_" + sParamId;
                hid.Value = isLeaf + "_" + menuId + "_" + rangeSet;
                tcell.Controls.Add(hid);

                span = new HtmlGenericControl();
                span.ID = "span_oper_" + sParamId;
                span.InnerHtml = "&nbsp;" + menuName + "&nbsp;";

                chk = new HtmlInputCheckBox();
                chk.ID = chkLayTwoId;
                if (isLeaf == "1")  //叶子节点
                {
                    if (!string.IsNullOrEmpty(ViewState["OPERPRV"].ToString()))
                    {
                        StringLib oString = new StringLib(ViewState["OPERPRV"].ToString());
                        bTwoCheck = oString.Contains(menuId);
                        oString = null;                        
                    }
                    else
                        bTwoCheck = false;
                }
                else
                    bTwoCheck = IsAllCheckedLayThree(modGroup,eTwoMenu);

                chk.Checked = bTwoCheck;
                if (bTwoCheckAll && !bTwoCheck) bTwoCheckAll = false;
                chk.Attributes.Add("onclick", "doCheckChange('" + chkLayTwoId + "')");
                chk.Attributes.Add("class", "checkbox");
                tcell.Controls.Add(chk);
                tcell.Controls.Add(span);

                if (isLeaf == "1" && rangeSet == "1")  //如果是叶子节点并且需要设置数据范围
                {
                    createDataRangeControls(ref tcell, sParamId, menuId, msRole);
                }

                trow.Cells.Add(tcell);
                tbPurview.Rows.Add(trow);

                if (isLeaf == "0")  //非叶子节点才有下级
                {
                    IEnumerable<MsMenu> threeQuery = modGroup.Where(m => (m.lay == "3") && 
                                                    m.layCode.Substring(0, 12).Equals(eTwoMenu.layCode));
                    createLayThreeOperMenus(threeQuery, sParamId, msRole);
                }

            }

            if (bTwoCheckAll) chkLayOne.Checked = true;
        }

        private bool IsAllCheckedLayThree(IGrouping<string, MsMenu> modGroup,MsMenu twoMenu)
        {
            string operMenuIds = ViewState["OPERPRV"].ToString();
            if (string.IsNullOrEmpty(operMenuIds)) return false;

            IEnumerable<MsMenu> threeQuery = modGroup.Where(m => (m.lay == "3") &&
                                                    m.layCode.Substring(0, 12).Equals(twoMenu.layCode));
            
            string menuId = string.Empty;
            StringLib oSelected = new StringLib(operMenuIds);
            bool bContain = true;
            foreach (MsMenu eThreeMenu in threeQuery)
            {                
                menuId = eThreeMenu.menuId;
                bContain = oSelected.Contains(menuId);
                if (!bContain) break;
            }

            oSelected = null;            
            return bContain;
        }

        private void createLayThreeOperMenus(IEnumerable<MsMenu> threeQuery, string sParamTwoId,MsRole msRole)
        {
            //if (null == oLayThrees) return;

            /* 创建菜单行规则:
             *   0. span : empty &nbsp;
             *   1. hidden : 存放参数.参数形式:leaf_menuid_DataRangeSign
             *              leaf 0: 非叶子; 1:叶子; 2: 模块 (为自定义，为编程方便，数据库中没此枚举值);
             *              menuid: 菜单Id
             *              DataRangeSign: 数据范围标志 0:不需要 1:需要设置             
             *   2. checkbox **/

            //XmlNode oLayThree;
            //int iCount = oLayThrees.Count;
            HtmlTableRow trow;
            HtmlTableCell tcell;
            HtmlInputHidden hid;
            HtmlInputCheckBox chk;
            HtmlGenericControl span;
            HtmlGenericControl spanEmpty;

            bool bCheck = false;
            string menuId = "";
            string menuName = "";
            string isLeaf = "";
            string rangeSet = "";  //数据范围标志
            string chkLayThreeId = "";

            foreach (MsMenu eThreeMenu in  threeQuery)
            {
                //oLayThree = oLayThrees[i];
                menuId = eThreeMenu.menuId;
                menuName = eThreeMenu.menuName;
                isLeaf = eThreeMenu.isLeaf;
                chkLayThreeId = "chk_oper_" + sParamTwoId + "_" + menuId;
                rangeSet = eThreeMenu.rangeSet;

                trow = new HtmlTableRow();
                trow.Attributes.Add("class", "darkrow3");
                tcell = new HtmlTableCell();
                spanEmpty = new HtmlGenericControl();
                spanEmpty.ID = "span_oper_empty_" + sParamTwoId + "_" + menuId;
                spanEmpty.InnerHtml = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                tcell.Controls.Add(spanEmpty);

                hid = new HtmlInputHidden();
                hid.ID = "hid_oper_param_" + sParamTwoId + "_" + menuId;
                hid.Value = isLeaf + "_" + menuId + "_" + rangeSet;
                tcell.Controls.Add(hid);

                //hid = new HtmlInputHidden();
                //hid.ID = sLayTwoId;
                //hid.Value = sMenuId;
                //tcell.Controls.Add(hid);

                span = new HtmlGenericControl();
                span.ID = "span_oper_" + sParamTwoId + "_" + menuId;
                span.InnerHtml = "&nbsp;" + menuName + "&nbsp;";

                if (!string.IsNullOrEmpty(ViewState["OPERPRV"].ToString()))
                {
                    StringLib oString = new StringLib(ViewState["OPERPRV"].ToString());
                    bCheck = oString.Contains(menuId);
                    oString = null;
                }
                else
                    bCheck = false;

                chk = new HtmlInputCheckBox();
                chk.ID = chkLayThreeId;
                chk.Checked = bCheck;
                chk.Attributes.Add("onclick", "doCheckChange('" + chkLayThreeId + "')");
                chk.Attributes.Add("class", "checkbox");
                tcell.Controls.Add(chk);
                tcell.Controls.Add(span);

                if (isLeaf == "1" && rangeSet == "1")  //需要设置数据范围
                {
                    createDataRangeControls(ref tcell, sParamTwoId + "_" + menuId, menuId, msRole);
                }

                trow.Cells.Add(tcell);
                tbPurview.Rows.Add(trow);
            }
        }

        private void createDataRangeControls(ref HtmlTableCell tcell, string suffixId, string menuId,MsRole msRole)
        {
            HtmlInputRadioButton radio;
            HtmlGenericControl span;
            HtmlInputHidden hidden;
            HtmlInputText text;
            HtmlAnchor anchor;
            HtmlImage image;

            string[] sRadioValueArray = new string[6];
            sRadioValueArray[0] = "9";
            sRadioValueArray[1] = "1";
            sRadioValueArray[2] = "2";
            sRadioValueArray[3] = "3";
            sRadioValueArray[4] = "0";
            sRadioValueArray[5] = "5";

            string[] sRadioTextArray = new string[6];
            sRadioTextArray[0] = "全部";
            sRadioTextArray[1] = "本部门";
            sRadioTextArray[2] = "本职位";
            sRadioTextArray[3] = "本级别";
            sRadioTextArray[4] = "本人";
            sRadioTextArray[5] = "自定义";

            string sDataRangeType = "";  //数据范围类型
            string sCtrlTypeId = "";
            string sCtrlRangeId = "";
            string sCtrlRangeName = "";
            sDataRangeType = getCustParamValue("DATARANGETYPE", menuId,msRole);
            sDataRangeType = (sDataRangeType != "") ? sDataRangeType : "9";  //默认选中全部 
            for (int i = 0; i < sRadioValueArray.Length; i++)
            {
                span = new HtmlGenericControl();
                span.ID = "span_oper_range" + suffixId + "_" + sRadioValueArray[i];
                span.InnerHtml = "&nbsp;" + sRadioTextArray[i] + "&nbsp;";
                radio = new HtmlInputRadioButton();
                radio.Name = "rd_oper_" + suffixId;
                radio.ID = "rd_oper_" + suffixId + "_" + sRadioValueArray[i];
                radio.Value = sRadioValueArray[i];
                radio.Attributes.Add("class", "radio");
                radio.Attributes.Add("onclick", "doSetRadio('" + radio.Name + "','" + suffixId + "')");
                if (sRadioValueArray[i] == sDataRangeType)
                    radio.Checked = true;

                tcell.Controls.Add(radio);
                tcell.Controls.Add(span);

                if (sRadioValueArray[i] == "5")  //自定义
                {
                    hidden = new HtmlInputHidden();
                    sCtrlTypeId = "hid_oper_range_type" + suffixId + "_" + sRadioValueArray[i];
                    hidden.ID = sCtrlTypeId;
                    hidden.Value = getCustParamValue("RANGETYPE", menuId, msRole);
                    tcell.Controls.Add(hidden);

                    hidden = new HtmlInputHidden();
                    sCtrlRangeId = "hid_oper_range_id" + suffixId + "_" + sRadioValueArray[i];
                    hidden.ID = sCtrlRangeId;
                    hidden.Value = getCustParamValue("RANGEID", menuId, msRole);
                    tcell.Controls.Add(hidden);

                    text = new HtmlInputText();
                    sCtrlRangeName = "txt_oper_range_name" + suffixId + "_" + sRadioValueArray[i];
                    text.ID = sCtrlRangeName;
                    text.Value = (hidden.Value.Equals("9")) ? "全部人员" : getCustParamValue("RANGENAME", menuId, msRole);
                    text.Attributes.Add("class", "inputreadonly");
                    tcell.Controls.Add(text);

                    image = new HtmlImage();
                    image.Src = "../images/toolbar/select.gif";
                    anchor = new HtmlAnchor();
                    anchor.HRef = "javascript:doSetCustRange('" + sCtrlTypeId + "','" + sCtrlRangeId + "','" + sCtrlRangeName + "','" + radio.Name + "')";
                    anchor.Controls.Add(image);
                    tcell.Controls.Add(anchor);
                }
            }
        }

        private string getCustParamValue(string sParamName, string menuId,MsRole msRole)
        {
            if (null == msRole || null == msRole.lstMenuPrv || msRole.lstMenuPrv.Count == 0) return string.Empty;

            MsPurview msPrv = msRole.lstMenuPrv.SingleOrDefault(m => m.menuId.Equals(menuId));
            if (null == msPrv) return string.Empty;

            string paramVal = string.Empty;
            switch (sParamName)
            {
                case "DATARANGETYPE":
                    paramVal = msPrv.rangeSign;
                    break;
                case "RANGETYPE":
                    paramVal = msPrv.custRangeType.ToString("D");
                    break;
                case "RANGEID":
                    paramVal = msPrv.custRangeIds;
                    break;
                case "RANGENAME":
                    paramVal = msPrv.custRangeNames;
                    break;
            }

            msPrv = null;
            return paramVal;
        }
        #endregion


        protected void lnbCallBack_Click(object sender, EventArgs e)
        {
            initializePage();
        }



        #region ajax methods
        /// <summary>
        /// 校验角色名是否存在
        /// </summary>
        /// <param name="sRoleName"></param>
        /// <param name="sRoleId"></param>
        /// <param name="sOrganId"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string CheckRoleNameExist(string roleName, string roleId, string organId, string userType)
        {
            RoleBLL roleBLL = new RoleBLL();
            eTrueFalse sysRole = (userType == "0") ? eTrueFalse.FALSE : eTrueFalse.TRUE;
            List<string> lstResult = roleBLL.IsExistRoleName(roleId, roleName, organId, sysRole);
            var newObj = new {
                OPERTYPE = "NAMECHECK",
                RSTSIGN = lstResult[0],
                RSTMSG = lstResult[1]
            };
            string serExpr = JavaScriptConvert.SerializeObject(newObj);

            newObj = null;
            lstResult = null;
            roleBLL.Release();
            roleBLL = null;
            return serExpr;
        }

        /// <summary>
        /// 保存角色信息
        /// </summary>
        /// <param name="strXML"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string SaveRole(string jsonExpr,string ctrlType)
        {
            MsRole msRole = JavaScriptConvert.DeserializeObject(jsonExpr, typeof(MsRole)) as MsRole;
            RoleBLL roleBLL = new RoleBLL();
            List<string> lstResult = roleBLL.Save(msRole);
            var newObj = new {
                OPERTYPE = "ROLESAVE",
                RSTSIGN = lstResult[0],
                RSTMSG = lstResult[1],
                CTRLTYPE = ctrlType
            };
            string serExpr = JavaScriptConvert.SerializeObject(newObj);

            newObj = null;
            lstResult = null;
            roleBLL.Release();
            roleBLL = null;
            return serExpr;
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="strRoleXML"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string DeleteRole(string roleId)
        {
            RoleBLL roleBLL = new RoleBLL();
            List<string> lstResult = roleBLL.Delete(roleId);
            var newObj = new {
                OPERTYPE = "ROLEDELETE",
                RSTSIGN = lstResult[0],
                RSTMSG = lstResult[1]
            };
            string serExpr = JavaScriptConvert.SerializeObject(newObj);

            newObj = null;
            lstResult = null;
            roleBLL.Release();
            roleBLL = null;
            return serExpr;
        }
        #endregion
    }
}
